﻿using System;
using PostSharp.Aspects;
using YuYuKiCms.Dal.Model;
using YuYuKiCms.Framework.Extention;
using YuYuKiCms.Framework.UnitTest;

namespace DALTest.Aspect
{
    [Serializable]
    public class InsertThemeAttribute : OnMethodBoundaryAspect
    {
        private readonly int _id;
        private readonly bool _isPathValid;
        private readonly bool _isSelected;
        private readonly string _lastUpdate;
        private readonly string _name;
        private readonly string _pageData;
        private readonly string _path;
        private readonly string _pathView;

        #region Overrides of OnMethodBoundaryAspect

        public InsertThemeAttribute(
            int id = 0,
            bool isPathValid = true,
            bool isSelected = true,
            string lastUpdate = "04/03/2014",
            string name = "newAge",
            string pageData = "some data",
            string path = "nothing",
            string pathView = "no view")
        {
            _id = id;
            _isPathValid = isPathValid;
            _isSelected = isSelected;
            _lastUpdate = lastUpdate;
            _name = name;
            _pageData = pageData;
            _path = path;
            _pathView = pathView;
        }

        public override void OnEntry(MethodExecutionArgs args)
        {
            var db = new YuyukiModel(Helper.ConnectionString);
            db.Add(new Theme
            {
                Id = _id,
                IsPathValid = _isPathValid,
                IsSelected = _isSelected,
                LastUpdate = _lastUpdate.ToDateTime(),
                Name = _name,
                PageData = _pageData,
                Path = _path,
                PathView = _pathView
            });
            db.SaveChanges();
        }

        #endregion
    }
}